<?php
namespace app\api\validate;

use think\exception\ValidateException;
use think\Request;
use think\Validate;

class BaseValidate extends Validate{
    protected $request;

    public function __construct(array $rules = [], $message = [], $field = [])
    {
        parent::__construct($rules, $message, $field);
        $this->request = Request::instance();

    }

    /**
     *检查返回的参数是否正确
     * @param $rule
     * @return mixed
     */
    public function goCheck($rule){
        $params = $this->request->param();
        $result = $this->check($params,$rule);
        if(!$result){
            throw new ValidateException($this->error);
        }else{
            return $params;
        }
    }

    /**
     *检查返回的参数是否正确
     * @param $scene ,验证场景
     * @return mixed
     */
    public function goCheckScene($scene){
        $params = $this->request->param();

        $result = $this->check($params,'',$scene);
        if(!$result){
            throw new ValidateException($this->error);
        }else{
            return $params;
        }
    }
}